/**
 * @file     MyStack.ts
 * @brief    [225. 用队列实现栈](https://leetcode.cn/problems/implement-stack-using-queues/description/)
 * @author   Zhu
 * @date     2022-11-05 20:49
 */

class MyStack {
    queue: number[];
    constructor() {
        this.queue = [];
    }

    push(x: number): void {
        let size = this.queue.length;
        this.queue.push(x);
        while (size--) {
            this.queue.push(this.queue.shift()!);
        }
    }

    pop(): number | undefined {
        return this.queue.shift();
    }

    top(): number {
        return this.queue[0];
    }

    empty(): boolean {
        return this.queue.length === 0;
    }
}

/**
 * Your MyStack object will be instantiated and called as such:
 * var obj = new MyStack()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.top()
 * var param_4 = obj.empty()
 */
